//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_createDialogMobile.sqf"
#include <btc_macros.h>
TRACE_1("Start",_this);

private ["_dlg_type","_r_dlg"];
DEFAULT_PARAM(_dlg_type,0,0);

if (_dlg_type != 0 || (BTC_active_lifes != 1 || BTC_lifes != 0)) then 
{
	if (_dlg_type == 0) then {
		player allowdamage false;
		deTach player;
		BTC_r_base_spawn setPos (markerPos BTC_respawn_marker);
		player attachTo [BTC_r_base_spawn,[0,0,10000]];
		player setVelocity [0,0,0];
		player setCaptive true;
		player enableSimulation false;
		player hideObjectGlobal true;
	};
	BTC_r_camera = "camera" camCreate (position BTC_r_base_spawn);
	BTC_r_camera camSetTarget BTC_r_base_spawn;
	BTC_r_camera cameraEffect ["internal", "BACK"];
	BTC_r_camera camSetPos (BTC_r_base_spawn modelToWorld [-15,-15,15]);
	BTC_r_camera camCommit 0;
	BTC_r_dlg_type = _dlg_type;
	BTC_r_chosen = false;
	BTC_r_list_names = [];
	BTC_r_list_objects = [];
	BTC_r_mobile_selected = objNull;
	titleText ["", "BLACK IN"];
	sleep 0.5;
	disableSerialization;
	closeDialog 0;
	_r_dlg = createDialog "BTCR_dlg_moveToMobile";
	sleep 0.5;
	titleText ["", "PLAIN"];
	waitUntil {dialog};
	[_dlg_type] call BTCR_fnc_updateRespawnLocations;
	while {!BTC_r_chosen && alive player} do
	{
		if (!dialog && !BTC_r_chosen) then {
			TRACE("Reopening Dialog");
			// We need to reset it. Otherwise we don't know the dialog is empty.
			BTC_r_list_names = [];
			_r_dlg = createDialog "BTCR_dlg_moveToMobile";sleep 0.5;
		};
		if (_dlg_type == 0) then {player attachTo [BTC_r_base_spawn,[0,0,10000]];};
		[_dlg_type] call BTCR_fnc_updateRespawnLocations;
		if (count BTC_r_list_names == 0) then {titleText ["NO SPAWN POINTS FOUND", "PLAIN"];};
		sleep 1;
	};
	if (_dlg_type == 0) then {
		player enableSimulation true;
		player allowdamage true;
		player setCaptive false;
		player hideObjectGlobal false;
	};
	closeDialog 0;
	player cameraEffect ["terminate","back"];
	camDestroy BTC_r_camera;
};
TRACE_1("End",ARR_3(BTC_r_dlg_type,BTC_r_chosen,BTC_r_mobile_selected));